package com.fc.v2.controller.gen;

import com.fc.v2.common.base.BaseController;
import com.fc.v2.common.domain.AjaxResult;
import com.fc.v2.common.domain.ResultTable;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.model.auto.Mechanism;
import com.fc.v2.service.MechanismService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import static com.fc.v2.common.domain.AjaxResult.successData;

/**
 * 机构表Controller
 * @ClassName: MechanismController
 * @author fuce
 * @date 2021-06-08 21:11:14
 */
@Api(value = "机构表")
@Controller
@RequestMapping("/MechanismController")
public class MechanismController extends BaseController{
	
	private String prefix = "gen/mechanism";
	
	@Autowired
	private MechanismService mechanismService;
	
	
	/**
	 * 机构表页面展示
	 * @param model
	 * @return String
	 * @author fuce
	 */
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/view")
	@RequiresPermissions("gen:mechanism:view")
    public String view(ModelMap model)
    {
        return prefix + "/list";
    }
	
	/**
	 * list集合
	 * @param tablepar
	 * @param searchText
	 * @return
	 */
	//@Log(title = "机构表", action = "111")
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/list")
	@RequiresPermissions("gen:mechanism:list")
	@ResponseBody
	public ResultTable list(Tablepar tablepar,Mechanism mechanism){
		PageInfo<Mechanism> page=mechanismService.list(tablepar,mechanism) ; 
		return pageTable(page.getList(),page.getTotal());
	}
	
	/**
     * 新增跳转
     */
	@ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }
	
    /**
     * 新增保存
     * @param 
     * @return
     */
	//@Log(title = "机构表新增", action = "111")
	@ApiOperation(value = "新增", notes = "新增")
	@PostMapping("/add")
	@RequiresPermissions("gen:mechanism:add")
	@ResponseBody
	public AjaxResult add(Mechanism mechanism){
		int b=mechanismService.insertSelective(mechanism);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 机构表删除
	 * @param ids
	 * @return
	 */
	//@Log(title = "机构表删除", action = "111")
	@ApiOperation(value = "删除", notes = "删除")
	@DeleteMapping("/remove")
	@RequiresPermissions("gen:mechanism:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=mechanismService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	
	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@ApiOperation(value = "修改跳转", notes = "修改跳转")
	@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map)
    {
        map.put("Mechanism", mechanismService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }
	
	/**
     * 修改保存
     */
    //@Log(title = "机构表修改", action = "111")
	@ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("gen:mechanism:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Mechanism mechanism)
    {
        return toAjax(mechanismService.updateByPrimaryKeySelective(mechanism));
    }

	@ApiOperation(value = "通过机构类型查机构", notes = "通过机构类型查机构")
	@GetMapping("/getEnableMechanismByTypeId")
	@ResponseBody
	public ResultTable getEnableMechanismByTypeId(Tablepar tablepar,Integer typeId){
		PageInfo<Mechanism> page=mechanismService.getEnableMechanismByTypeId(tablepar,typeId) ;
		return pageTable(page.getList(),page.getTotal());
	}

	@ApiOperation(value = "通过机构主键查机构详情", notes = "通过机构主键查机构详情")
	@GetMapping("/getMechanismInfoByPrimaryKey")
	@ResponseBody
	public AjaxResult getMechanismInfoByPrimaryKey(Integer id){
		return successData(200,mechanismService.getMechanismInfoByPrimaryKey(id));
	}

	@ApiOperation(value = "相关机构", notes = "相关机构")
	@GetMapping("/getOtherMechanism")
	@ResponseBody
	public ResultTable getOtherMechanism(Tablepar tablepar,Integer id){
		PageInfo<Mechanism> page=mechanismService.getOtherMechanism(tablepar,id) ;
		return pageTable(page.getList(),page.getTotal());
	}

	@ApiOperation(value = "课程详情里的机构", notes = "课程详情里的机构")
	@GetMapping("/getSingleMechanism")
	@ResponseBody
	public AjaxResult getSingleMechanism(Integer id){
		return successData(200,mechanismService.getSingleMechanism(id));
	}
}
